<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [
      { name: "xiaoming", age: 19 },
      { name: "xiaoming", age: 20 },
      { name: "xiaoming", age: 18 },
      { name: "xiaohong", age: 30 }
    ];

    const r = arr.reduce((acc, cur) => {
      // 第一次 acc => {}
      // cur.name => 'xiaoming'
      // acc[cur.name] => undefined
      // !acc[cur.name] => true
      if(!acc[cur.name] || cur.age > acc[cur.name].age) {
        /* {
          'xiaoming': { name: "xiaoming", age: 19 },
          'xiaohong': { name: "xiaohong", age: 30 }
        } */
        acc[cur.name] = cur
      }
      return acc
    }, {});

    console.log(Object.values(r));
  </script>
</body>

</html>